
// 渲染数据
$(function () {
    getUserInfo();
});

function getUserInfo(){
    var datas = {
        interface:'users@upUserInfo',
    };
    if(common.get('id')>0){
        datas.b_id = common.get('id');
    }
    common.ajax({
        data: datas,
        success: function (data) {
            if (data.status == '2000') {
                if(data.result.userInfo.u_true_name){
                    $('#userinfo').html(common.formatTemplate(data.result.userInfo,$('#userinfo').html()));
                }
                if(data.result.orderInfo.month_rent_amt){
                    $('#tenantinfo').html(common.formatTemplate(data.result.orderInfo,$('#tenantinfo').html()));
                }
                if (data.result.orderInfo.b_period) {
                    $('#fenqiinfo').html(common.formatTemplate(data.result.orderInfo, $('#fenqiinfo').html()));
                }
                if (data.result.orderInfo.month_rent_amt) {
                    $('#paymentinfo').html(common.formatTemplate(data.result.orderInfo, $('#paymentinfo').html()));
                }
                if(!data.result.userInfo.accountno && data.result.userInfo.is_open){
                    $('#submitMsg').text('去开通电子账户');
                    $("#submitMsg").off('click').on('click', function () {
                        openAccount(data.result.userInfo.is_auth);
                    });
                }else{
                    $("#submitMsg").off('click').on('click', function () {
                        submitMsg();
                    });
                }
            } else if (data.status == '5000') {
                falert(data.msg);
            }
        }
    });
}

//点击提交弹出遮罩层
function openAccount(type) {
    if(type){
        var flag = false;
        var datas = {
            interface:'fund@auth',
        };
        common.ajax({
            data: datas,
            success: function (data) {
                if(data.status == '2000'){
                    if(data.result.smscode_flag){
                        location.href = '/user/sendcore';
                    }else{
                        flag = true;
                    }
                } else if (data.status == '5000') {
                    falert(data.msg);
                }
            }
        });
        if(flag){
            var datas = {
                interface:'fund@open',
            };
            common.ajax({
                data: datas,
                success: function (data) {
                    if(data.status == '2000'){
                        location.href = data.result.url;
                    } else if (data.status == '5000') {
                        falert(data.msg);
                    }
                }
            });
        }
    }else{
        var datas = {
            interface:'fund@open',
        };
        common.ajax({
            data: datas,
            success: function (data) {
                if (data.status == '2000') {
                    if(data.result.isJump){
                        document.write(data.result.content);
                    }else{
                        $('#submitMsg').text('确认并提交');
                        $("#submitMsg").off('click').on('click', function () {
                            submitMsg();
                        });
                        falert('开户成功');
                    }
                } else if (data.status == '5000') {
                    falert(data.msg);
                }
            }
        });
    }
}

function tishi(){
    layer.open({
        type: 1,
        title: false,
        closeBtn: 0,
        skin: 'yourclass',
        scrollbar: false,
         btn:'知道了',success:function(layero){
          layero.find('.layui-layer-btn').css('text-align', 'center');
        },
        shadeClose: false,
        area: ['82%', '250px'],
        content: '交费日：以租房合同约定的每月交房租日期为准，该日期的前7天是您给蚂蚁白领交费的最后交费日。'
    });
}

//点击提交弹出遮罩层
function submitMsg() {
    layer.open({
        type: 1,
        title: false,
        closeBtn: 0,
        skin: 'yourclass',
        scrollbar: false,
        btn:['确认提交','暂不提交'],
        success:function(layero){
          layero.find('.layui-layer-btn').css('text-align', 'center');
        },
        shadeClose: false,
        area: ['82%', '250px'],
        content: '确认提交后，将为您生成缴费列表，请保证交费日当天银行卡内余额充足，届时系统会进行自动划扣。',
        btn1: function(index, layero){
            var datas = {
                interface:'order@saveOrder',
            };
            if(common.get('id')>0){
	        datas.b_id = common.get('id');
	    }
            common.ajax({
                data: datas,
                success: function (data) {
                    if (data.status == '2000') {
                        location.href = '/order/ordersuccess';
                    } else if (data.status == '5000') {
                        falert(data.msg);
                    }
                }
            });
        }
    });
}